//package edu.sctu.yueding.adapter;
//
//import android.content.Context;
//import android.support.v7.widget.RecyclerView;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.ImageView;
//
//import java.util.ArrayList;
//
//import edu.sctu.yueding.R;
//
///**
// * Created by wangfuxin on 2016/11/7.
// */
//
//public class IndexNewsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
//    private Context mContext;
//
//    private static final int TYPE_ITEM = 0;
//    private static final int TYPE_FOOTER = 1;
//
//    public IndexNewsAdapter(Context mContext) {
//        this.mContext = mContext;
//    }
//
//    public void refresh(ArrayList<String> data) {
//
//        this.notifyDataSetChanged();
//
//    }
//
//    @Override
//    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//
//        if (viewType == TYPE_ITEM) {
//
//            View view = LayoutInflater.from(parent.getContext()).inflate(
//                    R.layout.item_index_fragment_listview_news_v2, null);
//
//            view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT,
//                    RecyclerView.LayoutParams.WRAP_CONTENT));
//
//            return new ItemViewHolder(view);
//
//        } else if (viewType == TYPE_FOOTER) { // type == TYPE_FOOTER 返回footerView
//
//            View view = LayoutInflater.from(parent.getContext()).inflate(
//                    R.layout.xlistview_footer, null);
//
//            view.setLayoutParams(new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT,
//                    RecyclerView.LayoutParams.WRAP_CONTENT));
//
//            return new FooterViewHolder(view);
//
//        }
//
//
//        return null;
//    }
//
//
//    @Override
//    public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
//
//        if (holder instanceof ItemViewHolder) {
//
//
//
//        }
//
//
//    }
//
//    @Override
//    public int getItemViewType(int position) {
//        // 最后一个item设置为footerView
//        if (position + 1 == getItemCount()) {
//            return TYPE_FOOTER;
//        } else {
//            return TYPE_ITEM;
//        }
//    }
//
//    @Override
//    public int getItemCount() {
//        return 20;
//
//    }
//
//    class FooterViewHolder extends RecyclerView.ViewHolder {
//
//        public FooterViewHolder(View view) {
//            super(view);
//        }
//    }
//
//
//    class ItemViewHolder extends RecyclerView.ViewHolder {
//        ImageView imageView;
//
//        public ItemViewHolder(View itemView) {
//            super(itemView);
//            imageView = (ImageView) itemView.findViewById(R.id.item_news_img);
//        }
//    }
//}


package edu.sctu.yueding.adapter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import edu.sctu.yueding.R;
import edu.sctu.yueding.bean.HomeListViewBean;
import edu.sctu.yueding.utils.DateUtils;
import edu.sctu.yueding.utils.httputils.GetVolleyHttp;

/**
 * Created by wangfuxin on 2016/11/7.
 */

public class IndexNewsAdapter extends BaseAdapter {
    private Context mContext;
    private View view;
    private LayoutInflater layoutInflater;
    private ViewHolder viewHolder;
    private List<HomeListViewBean> data;


    public IndexNewsAdapter(Context mContext, List<HomeListViewBean> data) {
        this.mContext = mContext;
        this.data = data;
        layoutInflater = LayoutInflater.from(mContext);
    }

    /**
     * 刷新数据
     *
     * @param data
     */
    public void fresh(List<HomeListViewBean> data, boolean isAddAll) {
        Log.e("page", data.size() + "size");

        if (isAddAll) {
            this.data.addAll(data);
        } else {
            this.data = data;
        }
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {

        if (data != null && data.size() > 0) {
            return data.size();
        } else {
            return 0;
        }

    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            view = layoutInflater.inflate(R.layout.item_index_fragment_listview_news_v2, null);

            viewHolder = new ViewHolder();

            viewHolder.imageView = (ImageView) view.findViewById(R.id.item_news_img);

            view.setTag(viewHolder);//将viewHolder储存在view中
        } else {
            viewHolder = (ViewHolder) view.getTag();
            view = convertView;
        }

        GetVolleyHttp.getInstance((Activity) mContext).setImageLoader(viewHolder.imageView , R.drawable.photo_pictures_no,
                R.drawable.photo_pictures_no, data.get(position).getThumbnail());

//        viewHolder.imageView.setImageResource(R.drawable.logo);

        return view;
    }

    private class ViewHolder {
        ImageView imageView;
    }



}
